package logic

import (
	"context"
	"furni-manage/model/mysql"

	"furni-manage/goods/goods"
	"furni-manage/goods/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsDetailLogic {
	return &GoodsDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsDetailLogic) GoodsDetail(in *goods.GoodsDetailRequest) (*goods.GoodsDetailResponse, error) {
	// todo: add your logic here and delete this line
	var data mysql.Goods

	if err := data.FindGoodsById(mysql.DB, in.GoodsId); err != nil {
		return nil, err
	}
	return &goods.GoodsDetailResponse{
		GoodsName: data.Name,
		Price:     float32(data.Price),
		Num:       data.Num,
		Image:     data.Image,
	}, nil
}
